package com.yuexun.dhdoctor.module.meetingMaterial.presenter.impl;

import com.yuexun.dhdoctor.module.email.bean.MailFileBean;
import com.yuexun.dhdoctor.module.meetingMaterial.bean.MeetingMaterialDetailBean;
import com.yuexun.dhdoctor.module.meetingMaterial.model.IMeetingMaterialDetailModel;
import com.yuexun.dhdoctor.module.meetingMaterial.presenter.IMeetingMaterialDetailPresenter;
import com.yuexun.dhdoctor.module.meetingMaterial.ui.IMeetingMaterialDetailView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/11/15.
 */
public class MeetingMaterialDetailPresenter implements IMeetingMaterialDetailPresenter {
    IMeetingMaterialDetailView mView;
    IMeetingMaterialDetailModel mModel;

    public MeetingMaterialDetailPresenter(IMeetingMaterialDetailView view, IMeetingMaterialDetailModel model){
        this.mView=view;
        this.mModel=model;
    }

    @Override
    public void showMeetingMaterialDetail(String sessionUuid, Long meetingMaterialId) {
        mModel.inquireMeetingMaterialDetail(sessionUuid, meetingMaterialId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .filter(new Func1<MeetingMaterialDetailBean, Boolean>() {
                    @Override
                    public Boolean call(MeetingMaterialDetailBean meetingMaterialDetailBean) {
                        return Integer.parseInt(meetingMaterialDetailBean.getStatus())==200;
                    }
                })
                .subscribe(new Subscriber<MeetingMaterialDetailBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(MeetingMaterialDetailBean meetingMaterialDetailBean) {
                        mView.showMeetingMaterialDetail(meetingMaterialDetailBean.getDatas());
                    }
                });
    }

    @Override
    public void showFileDetail(String sessionUuid, String fileUuid) {
        mModel.getFileDetail(sessionUuid,fileUuid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .filter(new Func1<MailFileBean, Boolean>() {
                    @Override
                    public Boolean call(MailFileBean mailFileBean) {
                        return Integer.parseInt(mailFileBean.getStatus())==200;
                    }
                })
                .subscribe(new Subscriber<MailFileBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(MailFileBean mailFileBeen) {
                        mView.showFileDetail(mailFileBeen.getDatas());
                    }
                });
    }
}
